#!/bin/bash
echo -e "\033[31m使用此脚本前需要修改root密码并切换为root用户!\033[0m"
# 设置root密码，切换为root
#sudo passwd
#su - root

# 判断是否为root用户
if [ `whoami` != "root" ];then
    echo " only root can run it"
    exit 1
fi

# 判断能否访问外网
ping -c 2 www.baidu.com
if [ $? != 0  ];then
    echo "Please connect to the Internet!"
    exit 2
fi

# 开启ssh密码远程登录
sed -i 's/prohibit-password/yes/' /etc/ssh/sshd_config
systemctl restart sshd

# 配置阿里云软件源
cat > /etc/apt/sources.list <<-EOF
deb http://mirrors.aliyun.com/ubuntu/ xenial main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main

deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main

deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates universe

deb http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security universe
EOF
apt update

# 关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service

# 关闭selinux
setenforce 0 &> /dev/null
sed -i 's/enforcing/disabled/g' /etc/selinux/config &> /dev/null

# 安装常用工具
apt -y install vim gcc curl bash-completion lsof iotop unzip bzip2 tree man dos2unix lvm2 wget dnsutils
apt -y install make cmake autoconf net-tools psmisc rsync sudo lrzsz
source /usr/share/bash-completion/bash_completion

# 设置最大打开文件描述符数
sed -i  '/^exit/d' /etc/rc.local
echo "ulimit -SHn 65535" >> /etc/rc.local
echo "exit 0" >> /etc/rc.local
chmod +x /etc/rc.local
cat >> /etc/security/limits.conf <<-EOF
* soft nofile 65535
* hard nofile 65535
EOF

# 配置vim缩进
echo "set tabstop=4" >> /etc/vim/vimrc
echo "set softtabstop=4" >> /etc/vim/vimrc
echo "set shiftwidth=4" >> /etc/vim/vimrc

# 设置语言为中文
#localectl list-locales
#LANG=zh_CN.utf8
#localectl set-locale LANG=zh_CN.utf8

# 设置主机名
read -p "请输入您需要设置的主机名：" host_name
echo "$host_name" > /etc/hostname

echo -e "\033[31m 请自行配置IP地址！vim /etc/network/interfaces \033[0m"